#ifndef SERIALPORTDIALOG_H
#define SERIALPORTDIALOG_H

#include <QDialog>
#include <QtSerialPort/QSerialPort>

namespace Ui {
class SerialPortDialog;
}

class QIntValidator;

class SerialPortDialog : public QDialog
{
    Q_OBJECT

public:
    struct SerialPortSettings
    {
        QString     name;
        qint32      baudRate;
        QString     stringBaudRate;
        QSerialPort::DataBits       dataBits;
        QString     stringDataBits;
        QSerialPort::Parity         parity;
        QString     stringParity;
        QSerialPort::StopBits       stopBits;
        QString     stringStopBits;
        QSerialPort::FlowControl    flowControl;
        QString     stringFlowControl;
        bool localEchoEnabled;
    };

public:
    explicit SerialPortDialog(QWidget *parent = 0);
    ~SerialPortDialog();

    SerialPortSettings settings() const;

private:
    void fillPortsParameters();
    void fillPortsInfo();
    void updateSettings();

signals:
    void signalApply();

private slots:
    void slotShowPortInfo(int idx);
    void slotApply();
    void slotCheckCustomBaudRatePolicy(int idx);
    void slotCheckCustomDevicePathPolicy(int idex);

private:
    Ui::SerialPortDialog *ui;
    SerialPortSettings m_currentSettings;
    QIntValidator *m_intValidator;//内部验证程序
};

#endif // SERIALPORTDIALOG_H
